<template>
  <div class="casesCycle-box">
    <div class="subtitle-short casesCycle-titleSize">案件办理平均周期</div>
    <div id="table_casesCycle" class="casesCycle-tableSize"/>
  </div>
</template>

<script>
import echarts from "_echarts@4.9.0@echarts";

export default {
  name: "table_casesCycle",
  mounted() {
    this.tableInit_casesCycle()
  },
  methods: {
    tableInit_casesCycle() {
      const myChart = echarts.init(document.getElementById("table_casesCycle"))
      const posList = [
        'left',
        'right',
        'top',
        'bottom',
        'inside',
        'insideTop',
        'insideLeft',
        'insideRight',
        'insideBottom',
        'insideTopLeft',
        'insideTopRight',
        'insideBottomLeft',
        'insideBottomRight'
      ]
      let app = {}
      app.configParameters = {
        rotate: {
          min: -90,
          max: 90
        },
        align: {
          options: {
            left: 'left',
            center: 'center',
            right: 'right'
          }
        },
        verticalAlign: {
          options: {
            top: 'top',
            middle: 'middle',
            bottom: 'bottom'
          }
        },
        position: {
          options: posList.reduce(function (map, pos) {
            map[pos] = pos;
            return map;
          }, {})
        },
        distance: {
          min: 0,
          max: 100
        }
      };
      app.config = {
        rotate: 90,
        align: 'left',
        verticalAlign: 'middle',
        position: 'insideBottom',
        distance: 15,
        onChange: function () {
          const labelOption = {
            rotate: app.config.rotate,
            align: app.config.align,
            verticalAlign: app.config.verticalAlign,
            position: app.config.position,
            distance: app.config.distance
          };
          myChart.setOption({
            series: [
              {
                label: labelOption
              },
              {
                label: labelOption
              },
              {
                label: labelOption
              },
              {
                label: labelOption
              }
            ]
          });
        }
      };
      const labelOption = {
        show: false,
        position: app.config.position,
        distance: app.config.distance,
        align: app.config.align,
        verticalAlign: app.config.verticalAlign,
        rotate: app.config.rotate,
      };
      const option = {
        // 图表在容器内的位置
        grid: {
          top: '20%',
          right: '0%',
          bottom: '25%',
          left: '13%'
        },
        // 悬浮提示框
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        // X轴
        xAxis: [{
          type: 'category',
          boundaryGap: true,
          data: ['金华市', '兰溪市', '义乌市', '东阳市', '永康市', '武义市', '浦江市', '磐安市'],
          axisLabel: {  // 标签
            textStyle: {
              color: '#8c8c92',
            },
            interval: 0, //坐标刻度之间的显示间隔，默认就可以了（默认是不重叠）
            rotate: 60   //调整数值改变倾斜的幅度（范围-90到90）
          },
          axisLine: {
            show: true,
            lineStyle: {
              color: '#014C7D'
            }
          },
        }],
        yAxis: [
          {
            type: 'value',
            name: "时常:小时",
            min: 0,
            max: 50,
            interval: 10,
            nameTextStyle: {
              color: '#8c8c92',
              fontSize: 11,
              nameLocation: "start",
            },
            axisLabel: {  // 标签
              textStyle: {
                color: '#8c8c92',
              }
            },
            axisLine: {
              lineStyle: {
                color: '#014C7D'
              }
            },
            // 切割线
            splitLine: {
              show: true,
              lineStyle: {
                color: '#014C7D'
              }
            },
          }
        ],
        series: [
          {
            name: '单位',
            type: 'line',
            label: labelOption,
            emphasis: {
              focus: 'series'
            },
            barWidth: 7,
            data: [31, 26, 27, 41, 32, 28, 25, 29],
            areaStyle: {
              opacity: 0.6,
              color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
                offset: 0,
                color: "#08244C" // 0% 处的颜色
              }, {
                offset: 1,
                color: "#02A8F1" // 100% 处的颜色
              }], false),
            },
            itemStyle: {
              normal: {
                opacity: 1,
                barBorderRadius: [20, 20, 0, 0],
                color: "#02A8F1"
              }
            },
          },
        ]
      }
      option && myChart.setOption(option);
    },
  }
}
</script>

<style scoped>
.casesCycle-box {
  height: 33%;
  width: 100%;
}

.casesCycle-titleSize {
  height: 15%;
  line-height: 180%;
}

.casesCycle-tableSize {
  width: 100%;
  height: 80%;
  margin-top: 1%;
}
</style>
